﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Incendios0_1.Camera.wpfdatamanager;

namespace Incendios0_1.Camera.camera_management
{
    /// <summary>
    /// Interaction logic for Search_camera.xaml
    /// </summary>
    public partial class Search_camera : Window
    {
        private CameraData rCamera;
        private bool cancel;

        public Search_camera()
        {
            InitializeComponent();
            cancel = true; 
             rCamera = null;
        }

        private void searchCamera()
        {
            CameraData camera = CameraManager.SearchCamera(int.Parse(textBox1.Value.ToString()));
            if (camera == null)
            {
                Microsoft.Windows.Controls.MessageBox.Show("La camara no existe", "No encontrado", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                rCamera = camera;
                cancel = false;
                this.Close();
            }
        }

        internal CameraData SearchCam()
        {
            this.ShowDialog();
            return rCamera;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Search_Click(object sender, RoutedEventArgs e)
        {
            searchCamera();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (cancel)
                rCamera = null;
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                searchCamera();
        }
    }
}
